var mapInitialized = false;

function mapsLoaded() {  
  gmap = new google.maps.Map2(document.getElementById("map_div"), {size:new GSize(350,275)});
  gmap.setCenter(new google.maps.LatLng(41.006961, 29.046580), 12);
  gmap.enableDoubleClickZoom(); 
  gmap.enableContinuousZoom();
  gmap.enableScrollWheelZoom();                    
  
  gmap.addControl(new google.maps.ScaleControl());
  gmap.addControl(new google.maps.LargeMapControl());
  gmap.addControl(new google.maps.MapTypeControl());
        
  //mgr = new MarkerManager(gmap, {trackMarkers:true}); 
  
  google.maps.Event.addListener(gmap, 'click', function(overlay, latlng) {
          alert(latlng.lat() + '-' + latlng.lng());          
  });      
  
  google.maps.Event.addListener(gmap, 'moveend', function() {
          window.document.getElementById("sllInputHidden").value = gmap.getCenter();          
        });                         
    
  mapInitialized = true;
}

function createMarker(lat, lng) {  
   latlng = new GLatLng(lat, lng);    
   gmap.clearOverlays();
     
   gmap.addOverlay(new google.maps.Marker(latlng));   
   gmap.setCenter(latlng, 15);
}                     
    
function cme(index, name, latitude, longitude, streetaddress, region, city, country) {                      
  var si = window.document.getElementById('locSearchInput');
  si.value = name;
          
  createMarker(latitude, longitude);      
}     
    
function loadMaps() {
  google.load("maps", "2", {"callback" : mapsLoaded});
}

function initLoader() {
  var script = document.createElement("script");
  script.src = "http://www.google.com/jsapi?key=ABQIAAAA6PkGijZQl8bQ0xwCakOhKRRp0EPLZ06U0IjAPe16hUDFLTcm8RR0nciZV-g9Mj_rBY18jTmM_Yb87w&callback=loadMaps";
  script.type = "text/javascript";
  document.getElementsByTagName("head")[0].appendChild(script);  
}

function initializeMap() {
    if (!mapInitialized) {
        initLoader();
        loadMaps();
    }    
}

function showDlg(i)
{    
    var y=0;
    var pg = document.getElementById('modalPage');
    
    window.onscroll = function (e) {         
	if (self.pageYOffset) {
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop) {
		y = document.documentElement.scrollTop;
	}
	else if (document.body){
		y = document.body.clientHeight;
	}
                
        if (y > 1000) {
            pg.style.top = '0px';
        }
        else {
            pg.style.top = y + 'px';
        }
    };
        
    pg.style.top = y + 'px';
    pg.style.display = "block";
    
    if (i == 1) {
        document.getElementById('btn_renderp').click();
    }
    if (i == 2) {
        document.getElementById('btn_renderm').click();
        initializeMap();
    }
    if (i == 3) {
        document.getElementById('btn_renderv').click();            
    }
}

function hideDlg()
{
    document.getElementById('modalPage').style.display = "none";
}


function initializeAll() {
    MFEvent_hideAllDateSelections();
    MFEvent_showHideDateDetails();
}

function MFEvent_hideAllDateSelections() {
    var month = document.getElementById('MFEventMonth');
    var day = document.getElementById('MFEventDay');
    var at = document.getElementById('MFEventAt');
    var hour = document.getElementById('MFEventHour');
    var min = document.getElementById('MFEventMinute');    
    var colon = document.getElementById('MFEventColon');
    
    month.style.visibility = "hidden";
    month.style.display = "none";

    day.style.visibility = "hidden";
    day.style.display = "none";
        
    at.style.visibility = "hidden";        
    at.style.display = "none";
    
    hour.style.visibility = "hidden";        
    hour.style.display = "none";
        
    min.style.visibility = "hidden";
    min.style.display = "none";
        
    colon.style.visibility = "hidden";
    colon.style.display = "none";
}

function MFEvent_showHideDateDetails() {
    var i = document.getElementById('MFDateSelect').value;
    var month = document.getElementById('MFEventMonth');
    var day = document.getElementById('MFEventDay');
    var at = document.getElementById('MFEventAt');
    var hour = document.getElementById('MFEventHour');
    var min = document.getElementById('MFEventMinute');
    var colon = document.getElementById('MFEventColon');        
    
    MFEvent_hideAllDateSelections();
    if (i < 6 && i != 2) {
        hour.style.visibility = "visible";
        hour.style.display = "block";                
        min.style.visibility = "visible";
        min.style.display = "block";         
        at.style.visibility = "visible";
        at.style.display = "block";         
        colon.style.visibility = "visible";
        colon.style.display = "block";                
    }    
    else
    if (i == 6) {        
        month.style.visibility = "visible";
        month.style.display = "block";        
        day.style.visibility = "visible";
        day.style.display = "block";        
        at.style.visibility = "visible";
        at.style.display = "block";         
        hour.style.visibility = "visible";
        hour.style.display = "block";       
        colon.style.visibility = "visible";        
        colon.style.display = "block";
        min.style.visibility = "visible";
        min.style.display = "block";                
    }    
}